package com.halachawiki.client.login;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.halachawiki.shared.PermissionException;
import com.halachawiki.shared.PublicUserInfo;

@RemoteServiceRelativePath("login")
public interface LoginService  extends RemoteService {
	
	enum Status {
		OK,
		NO_SUCH_USER,
		USER_NOT_CONFIRMED,
		USER_NOT_APPROVED,
		USER_BANNED,
		WRONG_PASSWORD,
		NOT_LOGGED_IN,
		GENERIC_ERROR,
		ERROR_IVALID_PASSWORD
		// other error types
	}
	
	// User operations
	
	// Following APIs work also for users not logged in.
	// Security note: unlike most login systems, the model here is that the user doesn't have to 
	// remember if he has previously registered or not. He enters the email and then can tell (using
	// userExists()) if he is registered or not. This means we do expose some privacy information 
	// (whether user with given email is registered or not) publicly.
	
	// Returns only OK, NO_SUCH_USER, or error state. Non-confirmed/approved will also receive OK
	Status userExists(String email) throws IllegalArgumentException;
 	Status registerNewUser(String email, String password, String displayName, String aboutMe, String locale);
 	Status logInUser(String email, String password, boolean rememberMe);
 	Status sendPasswordReminder(String email);
	
 	// Following APIs work for all logged in users. 
 	// PublicUserInfo contains a detailed status (banned, not approved, not confirmed) that userExists()
 	// does not return.
	PublicUserInfo getCurrentUserInfo();	
 	Status sendApprovalReminder();
	boolean resendConfirmationEmail();
	Status confirmMe(String confirmationKey);
 	Status changePassword(String oldPassword, String newPassword); 	
 	void logout();
 	
 	// Admin operations
 	PublicUserInfo [] getAllUserInfo() throws PermissionException;
 	PublicUserInfo getUserInfo(String email) throws PermissionException;
 	Status banUser(String email) throws PermissionException;
 	Status unbanUser(String email) throws PermissionException;
 	Status approveUser(String email) throws PermissionException;
 	Status confirmUserEmail(String email) throws PermissionException;
 	Status changeUserEmail(String oldEmail, String newEmail) throws PermissionException;
 }
